package controllers;

import java.sql.Time;

public final class TimeDisp extends Time {

    public TimeDisp(Time time) {
        super(time.getTime());
    }

    public TimeDisp(int hr, int min) {
        super(hr, min, 0);
    }

    @Override
    public String toString() {
        int hour = super.getHours();
        int minute = super.getMinutes();
        String hourString;
        String minuteString;
        String ampm = "AM";

        //Determine AM or PM
        if (hour == 0) {
            hour += 12;
        } //if 0-1, set am
        else if (hour == 12) {
            ampm = "PM";
        } //if 12, set pm
        else if (hour > 12) {
            ampm = "PM";
            hour -= 12;
        } //if >12, subtract 12 set am

        //Create String and return
        if (hour < 10) {
            hourString = "0" + hour;
        } else {
            hourString = Integer.toString(hour);
        }
        if (minute < 10) {
            minuteString = "0" + minute;
        } else {
            minuteString = Integer.toString(minute);
        }
        return (hourString + ":" + minuteString + " " + ampm);
    }
}
